//
//  FourCategoryViewController.swift
//  CKC
//
//  Created by 张振东 on 2016/12/5.
//  Copyright © 2016年 ZZD. All rights reserved.
//

import UIKit

class FourCategoryViewController: UIViewController {

    
    let screenWidth = UIScreen.main.bounds.width
    let screenHeight = UIScreen.main.bounds.height
    var navigationHeight:CGFloat?

    
    //定义四个按钮
    var danXuanTiView:UIView?
    var panDuanTiView:UIView?
    var tianKongTiView:UIView?
    var tiaoZhanMoshiView:UIView?
    
    //定义四个按钮,分别添加与VIView上
    var danXuanTiBtn:UIButton?
    var panDuanTiBtn:UIButton?
    var tianKongTiBtn:UIButton?
    var tiaoZhanMoshiBtn:UIButton?
    
    //定义四个imageview,分别用于添加到UIView上
    var danXuanTiImageView:UIImageView?
    var panDuanImageView:UIImageView?
    var tianKongTiImageView:UIImageView?
    var tiaoZhanMoshiImageView:UIImageView?
    
    //定义四个label对象
    var danXuanTiLabel:UILabel?
    var panDuanTiLabel:UILabel?
    var tianKongTiLabel:UILabel?
    var tiaoZhanMoshiLabel:UILabel?
    
    
    override func viewDidLoad() {
        
        self.title = "笔形训练"
        self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.white,NSFontAttributeName:UIFont(name: "STHeitiSC-Medium", size: 20.0)!]
        
        self.view.backgroundColor = UIColor(red: 246,green: 246,blue: 246,alpha: 1)
        let leftBarButton = UIButton(frame:CGRect(x: 0,y: 0,width: 20,height: 20))
        leftBarButton.setBackgroundImage(UIImage(named: "fanhui"), for: UIControlState())
        leftBarButton.addTarget(self, action: #selector(backToPrevious), for: .touchUpInside)
        let leftBarButtonItem = UIBarButtonItem(customView: leftBarButton)
        self.navigationItem.leftBarButtonItems = [leftBarButtonItem]

        //获取导航栏的高度
        navigationHeight = self.navigationController?.navigationBar.bounds.size.height
        print(navigationHeight as Any)
        //初始化四个UIView对象
        danXuanTiView = UIView(frame: CGRect(x: 0, y: navigationHeight!+20, width: screenWidth/2, height: screenHeight/4))
        danXuanTiView?.backgroundColor = UIColor(red: 46/255,green: 204/255,blue: 113/255,alpha: 1)
        
        panDuanTiView = UIView(frame: CGRect(x: screenWidth/2, y: navigationHeight!+20, width: screenWidth/2, height: screenHeight/4))
        panDuanTiView?.backgroundColor = UIColor(red: 231/255,green: 76/255,blue: 60/255,alpha: 1)
        
        tianKongTiView = UIView(frame: CGRect(x: 0, y: navigationHeight!+20+screenHeight/4, width: screenWidth/2, height: screenHeight/4))
        tianKongTiView?.backgroundColor = UIColor(red: 243/255,green: 156/255,blue: 18/255,alpha: 1)
        
        tiaoZhanMoshiView = UIView(frame: CGRect(x: screenWidth/2, y: navigationHeight!+20+screenHeight/4, width: screenWidth/2, height: screenHeight/4))
        tiaoZhanMoshiView?.backgroundColor = UIColor(red: 142/255,green: 68/255,blue: 173/255,alpha: 1)
        
        //初始化四个按钮
        danXuanTiBtn = UIButton(frame: CGRect(x: 0, y: 0, width: screenWidth/2, height: screenHeight/4))
        panDuanTiBtn = UIButton(frame: CGRect(x: 0, y: 0, width: screenWidth/2, height: screenHeight/4))
        tianKongTiBtn = UIButton(frame: CGRect(x: 0, y: 0, width: screenWidth/2, height: screenHeight/4))
        tiaoZhanMoshiBtn = UIButton(frame: CGRect(x: 0,y: 0, width: screenWidth/2, height: screenHeight/4))
        
        //初始化三个imageView
        danXuanTiImageView = UIImageView(frame:CGRect(x:50,y:20,width:screenWidth/2-100,height: screenWidth/2-100))
        danXuanTiImageView!.contentMode = .scaleAspectFit
        let danXuanImage = UIImage(named: "danxuanti")
        danXuanTiImageView!.image = danXuanImage
        
        panDuanImageView = UIImageView(frame:CGRect(x:50,y:20,width:screenWidth/2-100,height: screenWidth/2-100))
        panDuanImageView!.contentMode = .scaleAspectFit
        let panDuanImage = UIImage(named: "panduanti")
        panDuanImageView!.image = panDuanImage

        
        tianKongTiImageView = UIImageView(frame:CGRect(x:50,y:20,width:screenWidth/2-100,height: screenWidth/2-100))
        tianKongTiImageView!.contentMode = .scaleAspectFit
        let tianKongImage = UIImage(named: "tiankong")
        tianKongTiImageView!.image = tianKongImage

        tiaoZhanMoshiImageView = UIImageView(frame:CGRect(x:50,y:20,width:screenWidth/2-100,height: screenWidth/2-100))
        tiaoZhanMoshiImageView!.contentMode = .scaleAspectFit
        let tiaoZhanMoshiImage = UIImage(named: "tiaozhan")
        tiaoZhanMoshiImageView!.image = tiaoZhanMoshiImage
        
        //初始化四个Label对象
        danXuanTiLabel = UILabel(frame:CGRect(x: 40,y: screenWidth/2-70,width: screenWidth/2-80,height: 30))
        danXuanTiLabel?.text = "单选题"
        danXuanTiLabel?.font = UIFont.systemFont(ofSize: 25)
        danXuanTiLabel?.textColor = UIColor.white
        
        panDuanTiLabel = UILabel(frame:CGRect(x: 40,y: screenWidth/2-70,width: screenWidth/2-80,height: 30))
        panDuanTiLabel?.text = "判断题"
        panDuanTiLabel?.font = UIFont.systemFont(ofSize: 25)
        panDuanTiLabel?.textColor = UIColor.white

        
        tianKongTiLabel = UILabel(frame:CGRect(x: 40,y: screenWidth/2-70,width: screenWidth/2-80,height: 30))
        tianKongTiLabel?.text = "填空题"
        tianKongTiLabel?.font = UIFont.systemFont(ofSize: 25)
        tianKongTiLabel?.textColor = UIColor.white
        
        tiaoZhanMoshiLabel = UILabel(frame:CGRect(x: 25,y: screenWidth/2-70,width: screenWidth/2-50,height: 30))
        tiaoZhanMoshiLabel?.text = "挑战模式"
        tiaoZhanMoshiLabel?.font = UIFont.systemFont(ofSize: 25)
        tiaoZhanMoshiLabel?.textColor = UIColor.white

        
        danXuanTiBtn?.addTarget(self, action: #selector(tiaoZhuanZhiDanXuanTi), for: .touchUpInside)
        panDuanTiBtn?.addTarget(self, action: #selector(tiaoZhuanZhiPanDuanTi), for: .touchUpInside)
        tianKongTiBtn?.addTarget(self, action: #selector(tiaoZhuanZhiTianKongTi), for: .touchUpInside)
        tiaoZhanMoshiBtn?.addTarget(self, action: #selector(tiaoZhuanZhiTiaoZhanMoshi), for: .touchUpInside)
        
        danXuanTiView?.addSubview(danXuanTiBtn!)
        panDuanTiView?.addSubview(panDuanTiBtn!)
        tianKongTiView?.addSubview(tianKongTiBtn!)
        tiaoZhanMoshiView?.addSubview(tiaoZhanMoshiBtn!)
        
        danXuanTiView?.addSubview(danXuanTiImageView!)
        panDuanTiView?.addSubview(panDuanImageView!)
        tianKongTiView?.addSubview(tianKongTiImageView!)
        tiaoZhanMoshiView?.addSubview(tiaoZhanMoshiImageView!)
        
        danXuanTiView?.addSubview(danXuanTiLabel!)
        panDuanTiView?.addSubview(panDuanTiLabel!)
        tianKongTiView?.addSubview(tianKongTiLabel!)
        tiaoZhanMoshiView?.addSubview(tiaoZhanMoshiLabel!)
        
        self.view.addSubview(danXuanTiView!)
        self.view.addSubview(panDuanTiView!)
        self.view.addSubview(tianKongTiView!)
        self.view.addSubview(tiaoZhanMoshiView!)
        
        
        
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    /*
        功能：跳转到单选题界面
     */
    func tiaoZhuanZhiDanXuanTi(){
        let biXingDanXuanTiViewController = BiXingDanXuanTiViewController()
        self.navigationController?.pushViewController(biXingDanXuanTiViewController, animated: true)
    }
    
    /*
     功能：跳转到判断题界面
     */
    func tiaoZhuanZhiPanDuanTi(){
        let biXingPanDuanTiViewController = BiXingPanDuanTiViewController()
        self.navigationController?.pushViewController(biXingPanDuanTiViewController, animated: true)
    }
    
    /*
     功能：跳转到填空题界面
     */
    func tiaoZhuanZhiTianKongTi(){
        let biXingTianKongTiViewController = BiXingTianKongTiViewController()
        self.navigationController?.pushViewController(biXingTianKongTiViewController, animated: true)
    }

    /*
     功能：跳转到笔形常规训练界面
     */
    func tiaoZhuanZhiTiaoZhanMoshi(){
        let biXingXunLianViewController = BiXingXunLianViewController()
        self.navigationController?.pushViewController(biXingXunLianViewController, animated: true)
    }

    func backToPrevious(){
        self.navigationController?.popViewController(animated: true)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
